/*
 * @lc app=leetcode.cn id=605 lang=javascript
 *
 * [605] 种花问题
 */

// @lc code=start
/**
 * @param {number[]} flowerbed
 * @param {number} n
 * @return {boolean}
 */
var canPlaceFlowers = function(flowerbed, n) {   
    let count=0
    let start=flowerbed.indexOf(1)
    let end=flowerbed.length-1- flowerbed.lastIndexOf(1)
    console.log(start,end)
    if(start==-1)return ((flowerbed.length+1)>>1)>=n
    count+=(start>>1)+(end>>1)
    console.log(count)
    let l=start
    while(l<= flowerbed.lastIndexOf(1)){
        l++
        if(flowerbed[l]==1){
            count+=(l-start-2)>>1
            start=l
        }
    }
    console.log(count)
    if(count>=n)return true
    else{return false}
};
// @lc code=end

